﻿using System.Collections.Generic;
using System.Net;

namespace Toybox.NicoSharp.Video
{
	using Primitives;
	using Utilities;

	partial class ChatCreator
	{
		public class PostKey : AbstractVideoKey
		{

			#region Constructor

			public PostKey(string thread, CookieCollection cookies)
				: base(thread, cookies)
			{
				this.BlockNo = -1;
			}

			#endregion Constructor


			#region Public Members

			public int BlockNo
			{
				get;
				set;
			}

			public override bool Expired
			{
				get { return true; }
			}

			#endregion Public Members


			#region Public Methods

			public string Update()
			{
				return base.Update(CreateUrl());
			}

			public void UpdateAsync()
			{
				base.UpdateAsync(CreateUrl());
			}

			protected virtual string CreateUrl()
			{
				Dictionary<string, string> dict = new Dictionary<string, string>();
				dict.Add("thread", this.Thread);
				dict.Add("block_no", this.BlockNo.ToString());
				dict.Add("yugi", string.Empty);

				return NicoUrls.FlApi + "getpostkey/?" + Serializer.AndEqualPairSerializer(dict);
			}

			#endregion Public Methods

			#region Override Methods

			protected override void SetKey(string text)
			{
				Value = text.Split('=')[1];
			}

			#endregion Override Methods

		}
	}
}